<?php
/**
 * Created by PhpStorm.
 * User: zhanglili
 * Date: 2021/9/6
 * Time: 16:22
 */

function get_onlineip()
{
    $ch = curl_init('http://tool.huixiang360.com/zhanzhang/ipaddress.php');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $a = curl_exec($ch);
    preg_match('/\[(.*)\]/', $a, $ip);

    return $ip[1];
}

function writeIp($str)
{
    $open = fopen("ip.txt", "w+");
    fwrite($open, $str);
    fclose($open);
}

function readIp()
{
    ini_set('display_errors', 1);
    if (is_file("ip.txt")) {

        $open = fopen("ip.txt", "r");
        $file_size = filesize("ip.txt");
        if (empty($file_size)) {
            return false;
        }
        $str = fread($open, filesize("ip.txt"));//指定读取大小，这里把整个文件内容读取出来
        fclose($open);
        return $str;
    }
    return false;
}